/**
 * 作用：导出Excel
 * 
 * @param {array} thead 
 * @param {array} tbody
 * @param {array} title
 * 
 * @returns
 */



export function export2Excel(thead, tbody, title) { // thead要传入表格的表头数据，tbody要传入表格的主体数据，title要传入excel的文件名
    require.ensure([], () => {
        const { export_json_to_excel } = require('../../utils/excel/Export2Excel');

        // Excel表头内容
        let tHeader = []
        // Excel主体内容
        let filterVal = []
        thead.forEach(item => {
            tHeader.push(item.label)
            filterVal.push(item.key)
        })
        const list = tbody;  //把表格数据存到list
        const data = formatJson(filterVal, list);
        export_json_to_excel(tHeader, data, title);

    })
}


function formatJson(filterVal, jsonData) {
    return jsonData.map(v => filterVal.map(j => v[j]))
}



